package cn.edu.scau.cmi.chenjiale.comprehension.service;

import java.util.List;

import cn.edu.scau.cmi.chenjiale.comprehension.dao.TeacherDAO;
import cn.edu.scau.cmi.chenjiale.comprehension.entity.Teacher;

/**
 * 教师操作业务类
 * 
 * @author chen.jiale
 * @date 2019/05/07
 *
 */
public class TeacherService {
	private TeacherDAO teacherDAO = new TeacherDAO();

	/**
	 * 添加教师
	 * 
	 * @param teacher
	 * @return
	 */
	public boolean add(Teacher teacher) {
		teacherDAO.save(teacher);
		return true;
	}

	/**
	 * 删除教师
	 * 
	 * @param teacher
	 * @return
	 */
	public boolean delete(Teacher teacher) {
		teacherDAO.delete(teacher);
		return true;
	}

	/**
	 * 修改教师
	 * 
	 * @param teacher
	 * @return
	 */
	public boolean update(Teacher teacher) {
		teacherDAO.attachDirty(teacher);
		return true;
	}

	/**
	 * 根据工号查询
	 * 
	 * @param id
	 * @return
	 */
	public Teacher findById(Long id) {
		Teacher teacher = teacherDAO.findById(id);
		return teacher;
	}

	/**
	 * 根据姓名查询
	 * 
	 * @param name
	 * @return
	 */
	public List findByName(String name) {
		List teachers = teacherDAO.findByName(name);
		return teachers;
	}

	/**
	 * 查询所有教师
	 * 
	 * @return
	 */
	public List findAll() {
		List teachers = teacherDAO.findAll();
		return teachers;
	}

	public static void main(String[] args) {
		TeacherService teacherService = new TeacherService();
		Teacher teacher = new Teacher();
		teacher.setName("chen.jiale");
		teacherService.add(teacher);
	}
}
